import request from '@/utils/axios';

import { RoleListRS, RoleWebModuleVO, RoleVO } from './types';

export const listApi = (data: any) => {
  return request.post<RoleListRS>({ url: '/system/role/list', data });
};

export const getApi = (id: string) => {
  return request.get<RoleVO>({ url: '/system/role/get/' + id });
};

export const saveApi = (data: RoleVO) => {
  return request.post({ url: '/system/role/save', data });
};

export const updateApi = (data: RoleVO) => {
  return request.post({ url: '/system/role/update', data });
};

export const removeApi = (id?: string) => {
  return request.post({ url: '/system/role/remove', params: { id } });
};

export const listWebModuleApi = (id: string) => {
  return request.get<RoleWebModuleVO>({
    url: '/system/role/listWebModule/' + id,
  });
};

export const updateModuleApi = (
  id: string | undefined,
  webModuleIds: string[] | undefined
) => {
  return request.post({
    url: '/system/role/updateModule',
    data: {
      id,
      webModuleIds: JSON.stringify(webModuleIds),
    },
  });
};

export const listAllApi = () => {
  return request.get<RoleVO[]>({ url: '/system/role/listAll' });
};
